export default {
  data() {
    return {
      pageLoading: false,
      status: 'loadmore',//懒加载
      id: 1,
      show: false,
      disabled: false,
      btnWidth: 180,
      firstLoading: false, // 首次加载控制空白默认图是否显示
      list: [],
      options: [{
        text: '取消收藏',
        style: {
          backgroundColor: 'rgb(235,92,2)',
          fontSize: '28rpx',
        }
      }],
      listIndex: 1,
      storeId: '', // 当前店铺id
    }
  },
  onReachBottom(){
    // 列表为空时，触底不请求
    // 加载更多状态为没有更多时nomore， 触底不请求
    if (this.list.length === 0) return false
    if (this.status === 'nomore') return false
    this.GetFollowList()
  },

  created() {
    this.storeId = this.$store.state.userInfoDetail.store.storeId
    this.GetFollowList()
  },

  methods: {
    // 加载前、中、后
    moreStatus(status) {
		  this.status = status
    },
    //收藏列表
    async GetFollowList() {
      let id = this.$store.state.userInfoDetail.store.storeId
      this.status = 'loading'
		  try {
        // uni.showLoading()

		    let data = {
          'PageIndex': this.listIndex,
          'PageSize': 10,
          'Store_Id': id
		    }
		    const res = await this.$api.busFollow.GetFollowListDataList(data)
		    console.log(res.data)
        this.list = [...this.list, ...res.data.list]
        this.firstLoading = this.list.length === 0
        this.$nextTick(() => {
          this.pageLoading = true
        })
        this.moreStatus(res.data.list.length >= 10 ? 'loadmore' : 'nomore')
        if (res.data.list.length !== 0) {
          this.listIndex += 1 // 当前页加1
        }
		  } catch (e) {
		    console.log(e)
		  }

    },

    // 收藏/取消收藏
    async collect(item) {
      try{
        let data = {
          store_id: item.store_Id,
          fans_store_id: this.storeId,
          state: false
        }
        const res = await this.$api.store.UpdateState(data)
        this.list = []
        this.listIndex = 1
        this.GetFollowList()
      } catch (e) {
        //TODO handle the exception
      }
    },

    click(data) {

      this.$u.toast('取消收藏')
      this.collect(data)
    },
    open(index) {
      console.log(index)
    },
  }
}
